using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace MacViet.DataBaseAPI
{	
	/// <summary>
	/// Description: Concrete DataProvider for table Bill_Detail. Provides atomic API functions.
	/// Author:  phong.huynh
	/// Created: 13/08/2010 10:56:02 SA
	/// </summary>
    public class BILL_DETAILDataAPI
	{
		private SQLHelper _dbTool = new SQLHelper();

		
		// ************************************
		// Implements function getByColumnName
		// ************************************
		
		public  DataTable getByBIL_ID(System.Int32 BIL_ID)
		{
            SqlParameter[] parm = { new SqlParameter(BILL_DETAILDTO._BIL_ID,BIL_ID)};
			return _dbTool.executeReader("SP_SEL_BILL_DETAIL_getByBIL_ID", parm);
		}
		

		
		public  DataTable getByBILL_ID(System.Int32 BILL_ID)
		{
            SqlParameter[] parm = { new SqlParameter(BILL_DETAILDTO._BILL_ID,BILL_ID)};
			return _dbTool.executeReader("SP_SEL_BILL_DETAIL_getByBILL_ID", parm);
		}
		
		public DataTable getByPRO_ID(System.Int32 PRO_ID)
		{
            SqlParameter[] parm = { new SqlParameter(BILL_DETAILDTO._PRO_ID,PRO_ID)};
			return _dbTool.executeReader("SP_SEL_BILL_DETAIL_getByPRO_ID", parm);
		}		
		


		// *************************************************
		// Implement function getAll/getByDynamicCondition
		// *************************************************

		public DataTable getAll()
		{
			return _dbTool.executeReader("SP_SEL_BILL_DETAIL_getAll");
		}


		
		// ********************************************************
		// Implement function getByPrimaryKeys / getByForeignKeys
		// In case table have composite primary/foreign keys
		// ********************************************************

		public  DataTable getByPrimaryKeys(System.Int32 BIL_ID )
		{
            SqlParameter[] parm = { new SqlParameter(BILL_DETAILDTO._BIL_ID,BIL_ID)};
			return _dbTool.executeReader("SP_SEL_BILL_DETAIL_getByPrimaryKeys",parm);
		}


		public  bool insertBILL_DETAIL( System.Int32 BILL_ID, System.Int32 PRO_ID, System.Int32 BIL_PROQUANTITY, System.Decimal BIL_AMOUNT)
		{
            SqlParameter[] parm = { new SqlParameter(BILL_DETAILDTO._BIL_ID,1),
                                  new SqlParameter(BILL_DETAILDTO._BILL_ID,BILL_ID),
                                  new SqlParameter(BILL_DETAILDTO._PRO_ID,PRO_ID),
                                  new SqlParameter(BILL_DETAILDTO._BIL_PROQUANTITY,BIL_PROQUANTITY),
                                  new SqlParameter(BILL_DETAILDTO._BIL_AMOUNT,BIL_AMOUNT)};
			int effectedRows = _dbTool.ExecuteNoneQuery("SP_INS_BILL_DETAIL_values", parm);
			
			
			

			return (effectedRows == 1);
		}


		///<summary>		
		/// Thu+.c hie^.n ca^u le^.nh update du+.a tre^n kho'a chi'nh
		///</summary>

		public  bool updateBILL_DETAIL(System.Int32 BIL_ID , System.Int32 BILL_ID, System.Int32 PRO_ID, System.Int32 BIL_PROQUANTITY, System.Decimal BIL_AMOUNT)
		{
            SqlParameter[] parm = { new SqlParameter(BILL_DETAILDTO._BIL_ID,BIL_ID),
                                  new SqlParameter(BILL_DETAILDTO._BILL_ID,BILL_ID),
                                  new SqlParameter(BILL_DETAILDTO._PRO_ID,PRO_ID),
                                  new SqlParameter(BILL_DETAILDTO._BIL_PROQUANTITY,BIL_PROQUANTITY),
                                  new SqlParameter(BILL_DETAILDTO._BIL_AMOUNT,BIL_AMOUNT)};
			int affectRows = _dbTool.ExecuteNoneQuery("SP_UDP_BILL_DETAIL_update", parm);

			return affectRows == 1;
		}

		

		// ********************************************************************************
		// Implementation of deleteAll/deteleByForeignKeys/deleteByPrimaryKeys function		
		// ********************************************************************************

		// return number of deleted rows		
		public  int deleteAll()
		{
			return _dbTool.ExecuteNoneQuery("SP_DEL_BILL_DETAIL_deleteAll");
		}

		// return number of deleted rows
		public  int deleteByPrimaryKeys(System.Int32 BIL_ID )
		{
            SqlParameter[] parm = { new SqlParameter(BILL_DETAILDTO._BIL_ID,BIL_ID)};
			return _dbTool.ExecuteNoneQuery("SP_DEL_BILL_DETAIL_deleteByPrimaryKeys",parm);
		}

		
	}
}